﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace Wys.DataForm.CSharp
{
    public partial class ChildSelect : Wys.Control.Vb.AutoAdjustFrom
    {
        public ChildSelect()
        {
            InitializeComponent();
        }

        String _ClassName = String.Empty;
        public  String ClassName1
        {
            get
            {
                return _ClassName;
            }
            set
            {
                _ClassName = value;
            }
        }

        String _Title = String.Empty;
        public String Title
        {
            get
            {
                return _Title;
            }
            set
            {
                _Title = value;
            }
        }
        String _DllName = String.Empty;
        public String DllName
        {
            get
            {
                return _DllName;
            }
            set
            {
                _DllName = value;
            }
        }

        public bool 是否外部
        {
            get
            {
                return rad是否外部.Checked;
            }
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (System.IO.File.Exists(this.txtPath.Text.TrimEnd()))
                {
                    OpenFileDialog1.FileName = this.txtPath.Text.TrimEnd();
                }
                if (this.OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    this.lstClass.Items.Clear();
                    this.txtPath.Text = this.OpenFileDialog1.FileName;
                    System.Reflection.Assembly tempas = System.Reflection.Assembly.LoadFile(this.txtPath.Text);
                    //设置属性         
                    DllName = System.IO.Path.GetFileName(txtPath.Text);
                    foreach (Type ty in tempas.GetExportedTypes())
                    {
                        if (GetExistType(ty, "Wys.Control.Vb.AutoAdjustFrom"))
                        {
                            this.lstClass.Items.Add(ty.FullName);
                        }
                        else if(GetExistType(ty,"System.Windows.Forms.Form"))
                        {
                            this.lstClass.Items.Add(ty.FullName);
                        }
                    }

                }
            }
            catch (Exception me)
            {
                //SaveException(me); //D-2009-10-11
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                this.ClassName1 = lstClass.SelectedItems[0].Text;
            }
            catch (Exception me)
            {
                this.ClassName1 = String.Empty;
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }
            
            this.Title = this.txtTitle.Text;
            this.Close();
        }

        private void ChildSelect_Load(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(this.txtPath.Text.TrimEnd()))
            {
                this.lstClass.Items.Clear();
                System.Reflection.Assembly tempas = System.Reflection.Assembly.LoadFile(this.txtPath.Text);
                //设置属性         
                DllName = System.IO.Path.GetFileName(txtPath.Text);
                foreach (Type ty in tempas.GetExportedTypes())
                {
                    if (GetExistType(ty, "Wys.Control.Vb.AutoAdjustFrom"))
                    {
                        this.lstClass.Items.Add(ty.FullName);
                    }
                }
            }
        }
    }
}
